package UI;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/**
 * Utility class for UI shell manipulation.
 */
public class SWTUtil
{
	/**
	 * Static display
	 */
	private static Display display = new Display();
	
	/**
	 * Creates a simple empty shell.
	 * 
	 * @return The new empty shell
	 */
	public static Shell createSimpleShell()
	{
		return new Shell(display);
	}
	
	/**
	 * Returns the static display instance.
	 * 
	 * @return The static display instance
	 */
	public static Display getDisplay()
	{
		return display;
	}
	
	/**
	 * Opens the given shell, and runs the standard event loop in order to keep the shell open until closed explicitly.
	 * When the shell is closed it gets disposed.
	 * 
	 * @param shell The shell to display.
	 */
	public static void openShell(Shell shell)
	{
		shell.open();
		
		while (!shell.isDisposed())
		{
			if (!display.readAndDispatch())
			{
				display.sleep();
			}
		}
		
		shell.dispose();
	}
}
